

************************************************************************************************************************
*------------------------------------------------------------------------------*
* Clean Consumer July 
*------------------------------------------------------------------------------*
************************************************************************************************************************

insheet using "data/source/Consumers_Cryptocurrency and Blockchain Survey July 2018_import.csv",clear name

*----- Drop variable label
drop if household_id == ""
drop if household_id == "Respondent ID"
destring household_id, replace force

*----- Format the date
rename date date_o
gen date = date(date_o,"MDY")
order date
format date %td


*----- Drop individual bullish_sector
drop v*


*----- Combine the three individual questions into one
* quantity
gen quantity = ""
replace quantity = quantity_1

* expectations value
gen expectationsvalue = expectationsvalue_1 +expectationsvalue_2 + expectationsvalue_3

* typeobjective 
gen typeobjective = "consumer"

* typeselfreport
gen typeselfreport = typeselfreport_1 +typeselfreport_2 + typeselfreport_3

* age
gen age = age_1 +age_2 + age_3

* country
gen country = country_1 +country_2 + country_3

* income
gen income = income_1 +income_2 + income_3

* amazon_mechanical_turk_id 
gen amazon_mechanical_turk_id  = amazon_mechanical_turk_id_1 +amazon_mechanical_turk_id_2 

* plan_to_purchase_12_months
gen plan_to_purchase_12_months = plan_to_purchase_12_months_2 + plan_to_purchase_12_months_3

* first_purchase_time 
gen first_purchase_time  = first_purchase_time_1

* plan_to_increase_holding
gen plan_to_increase_holding = plan_to_increase_holding_1

* accept_across_industry
gen accept_across_industry = accept_across_industry_1 +accept_across_industry_2 + accept_across_industry_3

* how_long_to_be_mainstream
gen how_long_to_be_mainstream = how_long_to_be_mainstream_1 +how_long_to_be_mainstream_2 + how_long_to_be_mainstream_3

* company_consider_implement
gen company_consider_implement = company_consider_implement_1 +company_consider_implement_2 + company_consider_implement_3

* bullish_sector
gen bullish_sector = bullish_sector_1 +bullish_sector_2 + bullish_sector_3


*----- Keep if the keep variable 
keep household_id choice* currencies_potential* quantity expectationsvalue typeobjective ///
typeselfreport age country income date amazon_mechanical_turk_id  ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector


*----- expand to different currency 
expand 11
bys household_id: gen currency = _n
order currency,after(household_id)

tostring currency, replace force
replace currency = "ALT" if currency == "1"
replace currency = "bitcoin" if currency == "2"
replace currency = "bitcoin-cash" if currency == "3"
replace currency = "bytecoin-bcn" if currency == "4"
replace currency = "dash" if currency == "5"
replace currency = "ethereum" if currency == "6"
replace currency = "litecoin" if currency == "7"
replace currency = "monero" if currency == "8"
replace currency = "ripple" if currency == "9"
replace currency = "swftcoin" if currency == "10"
replace currency = "zcash" if currency == "11"


*----- Choice
gen choice = 0
order choice, after(currency)

replace choice = 1 if currency == "bitcoin" 		& choice1_1 != ""
replace choice = 1 if currency == "ethereum" 		& choice1_2 != ""
replace choice = 1 if currency == "litecoin" 		& choice1_3 != ""
replace choice = 1 if currency == "ripple" 			& choice1_4 != ""
replace choice = 1 if currency == "zcash" 			& choice1_5 != ""
replace choice = 1 if currency == "dash" 			& choice1_6 != ""
replace choice = 1 if currency == "monero" 			& choice1_7 != ""
replace choice = 1 if currency == "swftcoin" 		& choice1_8 != ""
replace choice = 1 if currency == "bitcoin-cash" 	& choice1_9 != ""
replace choice = 1 if currency == "bytecoin-bcn" 	& choice1_10 != ""
replace choice = 1 if currency == "ALT" 			& choice1_12 != "" 


*----- currencies_potential
gen currencies_potential = 0
order currencies_potential, after(choice)

br household_id currency currencies_potential currencies_potential_3_*

replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_1_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_1_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_1_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & currencies_potential_1_4 == "Ripple (XRP)"
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_1_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_1_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_1_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_1_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_1_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_1_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_1_13 != ""


replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_3_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_3_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_3_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & currencies_potential_3_4 == "Ripple (XRP)"
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_3_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_3_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_3_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_3_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_3_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_3_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_3_13 != "" ///
                                                      & indexnot("I don't think",currencies_potential_3_13) !=0 ///
													  & indexnot("None",currencies_potential_3_13) !=0 ///
													  & indexnot("Not Invented",currencies_potential_3_13) !=0


*----- Keep if the keep variable
keep household_id currency choice currencies_potential quantity expectationsvalue typeobjective ///
typeselfreport age country income date amazon_mechanical_turk_id  ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector


save "data/working/adjusted_consumer_july",replace



************************************************************************************************************************
*------------------------------------------------------------------------------*
* Clean Consumer Jan
*------------------------------------------------------------------------------*
************************************************************************************************************************

insheet using "data/source/Consumers_Raw Data_Jan 2018_import.csv",clear name

*----- Drop variable label
drop if household_id == .

*----- Format the date
rename date date_o
gen date = date(date_o,"MDY")
order date
format date %td


*----- Drop individual bullish_sector
drop v*


*----- Combine the three individual questions into one
* quantity
gen quantity = ""
replace quantity = quantity_1

* expectations value
gen expectationsvalue = expectationsvalue_1 +expectationsvalue_2 + expectationsvalue_3

* typeobjective 
gen typeobjective = "consumer"

* typeselfreport
gen typeselfreport = typeselfreport_1 +typeselfreport_2 + typeselfreport_3

* age
gen age = age_1 +age_2 + age_3

* country
gen country = country_1 +country_2 + country_3

* income
gen income = income_1 +income_2 + income_3

* amazon_mechanical_turk_id 
gen amazon_mechanical_turk_id  = amazon_mechanical_turk_id_1 +amazon_mechanical_turk_id_2 

* plan_to_purchase_12_months
gen plan_to_purchase_12_months = plan_to_purchase_12_months_2 + plan_to_purchase_12_months_3

* first_purchase_time 
gen first_purchase_time  = first_purchase_time_1

* plan_to_increase_holding
gen plan_to_increase_holding = plan_to_increase_holding_1

* accept_across_industry
gen accept_across_industry = accept_across_industry_1 +accept_across_industry_2 + accept_across_industry_3

* how_long_to_be_mainstream
gen how_long_to_be_mainstream = how_long_to_be_mainstream_1 +how_long_to_be_mainstream_2 + how_long_to_be_mainstream_3

* company_consider_implement
gen company_consider_implement = company_consider_implement_1 +company_consider_implement_2 + company_consider_implement_3

* bullish_sector
gen bullish_sector = bullish_sector_1 +bullish_sector_2 + bullish_sector_3


*----- Keep if the keep variable 
keep household_id choice* currencies_potential* quantity expectationsvalue typeobjective ///
typeselfreport age country income date amazon_mechanical_turk_id  ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector


*----- expand to different currency 
expand 11
bys household_id: gen currency = _n
order currency,after(household_id)

tostring currency, replace force
replace currency = "ALT" if currency == "1"
replace currency = "bitcoin" if currency == "2"
replace currency = "bitcoin-cash" if currency == "3"
replace currency = "bytecoin-bcn" if currency == "4"
replace currency = "dash" if currency == "5"
replace currency = "ethereum" if currency == "6"
replace currency = "litecoin" if currency == "7"
replace currency = "monero" if currency == "8"
replace currency = "ripple" if currency == "9"
replace currency = "swftcoin" if currency == "10"
replace currency = "zcash" if currency == "11"


*----- Choice
gen choice = 0
order choice, after(currency)

replace choice = 1 if currency == "bitcoin" 		& choice1_1 != ""
replace choice = 1 if currency == "ethereum" 		& choice1_2 != ""
replace choice = 1 if currency == "litecoin" 		& choice1_3 != ""
replace choice = 1 if currency == "ripple" 			& choice1_4 != ""
replace choice = 1 if currency == "zcash" 			& choice1_5 != ""
replace choice = 1 if currency == "dash" 			& choice1_6 != ""
replace choice = 1 if currency == "monero" 			& choice1_7 != ""
replace choice = 1 if currency == "swftcoin" 		& choice1_8 != ""
replace choice = 1 if currency == "bitcoin-cash" 	& choice1_9 != ""
replace choice = 1 if currency == "bytecoin-bcn" 	& choice1_10 != ""
replace choice = 1 if currency == "ALT" 			& choice1_12 != ""


*----- currencies_potential
gen currencies_potential = 0
order currencies_potential, after(choice)

br household_id currency currencies_potential currencies_potential_3_*

replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_1_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_1_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_1_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & currencies_potential_1_4 == "Ripple (XRP)"
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_1_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_1_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_1_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_1_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_1_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_1_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_1_13 != ""


replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_3_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_3_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_3_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & currencies_potential_3_4 == "Ripple (XRP)"
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_3_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_3_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_3_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_3_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_3_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_3_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_3_13 != "" ///
                                                      & indexnot("I dont know",currencies_potential_3_13) !=0 ///
													  & indexnot("no else",currencies_potential_3_13) !=0 ///
													  & indexnot("none will succeed",currencies_potential_3_13) !=0 ///
													  & indexnot("none of them",currencies_potential_3_13) !=0 




*----- Keep if the keep variable
keep household_id currency choice currencies_potential quantity expectationsvalue typeobjective ///
typeselfreport age country income date amazon_mechanical_turk_id  ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector


save "data/working/adjusted_consumer_jan",replace


************************************************************************************************************************
*------------------------------------------------------------------------------*
* Clean Investors (Jan and July for investors are appended and saved as: "Investors_Raw_Data_JanJuly2018_import.csv")
*------------------------------------------------------------------------------*
************************************************************************************************************************

insheet using "data/source/Investors_Raw_Data_JanJuly2018_import.csv",clear name

*----- Drop variable label
drop if household_id == .

*----- Format the date
rename date date_o
gen date = date(date_o,"MDY")
order date
format date %td


*----- Drop individual bullish_sector
drop v*


*----- Combine the three individual questions into one
* quantity
gen quantity = ""
replace quantity = quantity_1

* expectations value
gen expectationsvalue = expectationsvalue_1 +expectationsvalue_2 + expectationsvalue_3

* typeobjective 
gen typeobjective = "investor"

* typeselfreport
gen typeselfreport = typeselfreport_1 +typeselfreport_2 + typeselfreport_3

* age
gen age = age_1 +age_2 + age_3

* country
gen country = country_1 +country_2 + country_3

* income
gen income = income_1 +income_2 + income_3

* plan_to_purchase_12_months
gen plan_to_purchase_12_months = plan_to_purchase_12_months_2 + plan_to_purchase_12_months_3

* first_purchase_time 
gen first_purchase_time  = first_purchase_time_1

* plan_to_increase_holding
gen plan_to_increase_holding = plan_to_increase_holding_1

* accept_across_industry
gen accept_across_industry = accept_across_industry_1 +accept_across_industry_2 + accept_across_industry_3

* how_long_to_be_mainstream
gen how_long_to_be_mainstream = how_long_to_be_mainstream_1 +how_long_to_be_mainstream_2 + how_long_to_be_mainstream_3

* company_consider_implement
gen company_consider_implement = company_consider_implement_1 +company_consider_implement_2 + company_consider_implement_3

* bullish_sector
gen bullish_sector = bullish_sector_1 +bullish_sector_2 + bullish_sector_3


*----- Keep if the keep variable 
keep household_id choice* currencies_potential* quantity expectationsvalue typeobjective ///
typeselfreport age country income date   ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector


*----- expand to different currency 
expand 11
bys household_id: gen currency = _n
order currency,after(household_id)

tostring currency, replace force
replace currency = "ALT" if currency == "1"
replace currency = "bitcoin" if currency == "2"
replace currency = "bitcoin-cash" if currency == "3"
replace currency = "bytecoin-bcn" if currency == "4"
replace currency = "dash" if currency == "5"
replace currency = "ethereum" if currency == "6"
replace currency = "litecoin" if currency == "7"
replace currency = "monero" if currency == "8"
replace currency = "ripple" if currency == "9"
replace currency = "swftcoin" if currency == "10"
replace currency = "zcash" if currency == "11"


*----- Choice
gen choice = 0
order choice, after(currency)

replace choice = 1 if currency == "bitcoin" 		& choice1_1 != ""
replace choice = 1 if currency == "ethereum" 		& choice1_2 != ""
replace choice = 1 if currency == "litecoin" 		& choice1_3 != ""
replace choice = 1 if currency == "ripple" 			& choice1_4 != ""
replace choice = 1 if currency == "zcash" 			& choice1_5 != ""
replace choice = 1 if currency == "dash" 			& choice1_6 != ""
replace choice = 1 if currency == "monero" 			& choice1_7 != ""
replace choice = 1 if currency == "swftcoin" 		& choice1_8 != ""
replace choice = 1 if currency == "bitcoin-cash" 	& choice1_9 != ""
replace choice = 1 if currency == "bytecoin-bcn" 	& choice1_10 != ""
replace choice = 1 if currency == "ALT" 			& choice1_12 != ""


*----- currencies_potential
gen currencies_potential = 0
order currencies_potential, after(choice)

br household_id currency currencies_potential currencies_potential_1_* currencies_potential_3_*

replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_1_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_1_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_1_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & (currencies_potential_1_4 == "XRP (Ripple)" |currencies_potential_1_4 == "Ripple (XRP)")
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_1_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_1_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_1_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_1_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_1_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_1_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_1_13 != ""

replace currencies_potential = 1 if currency == "bitcoin" & currencies_potential_3_1 == "Bitcoin"
replace currencies_potential = 1 if currency == "ethereum" & currencies_potential_3_2 == "Ethereum"
replace currencies_potential = 1 if currency == "litecoin" & currencies_potential_3_3 == "Litecoin"
replace currencies_potential = 1 if currency == "ripple" & (currencies_potential_3_4 == "XRP (Ripple)" | currencies_potential_3_4 == "Ripple (XRP)")
replace currencies_potential = 1 if currency == "zcash" & currencies_potential_3_5 == "Zcash"
replace currencies_potential = 1 if currency == "dash" & currencies_potential_3_6 == "Dash"
replace currencies_potential = 1 if currency == "monero" & currencies_potential_3_7 == "Monero"
replace currencies_potential = 1 if currency == "swftcoin" & currencies_potential_3_8 == "Swiftcoin"
replace currencies_potential = 1 if currency == "bitcoin-cash" & currencies_potential_3_9 == "Bitcoin Cash"
replace currencies_potential = 1 if currency == "bytecoin-bcn" & currencies_potential_3_10 == "Bytecoin"
replace currencies_potential = 1 if currency == "ALT" & currencies_potential_3_13 != "" ///
                                                      & indexnot("I do not know",currencies_potential_3_13) !=0 ///
													  & indexnot("NONE LONG",currencies_potential_3_13) !=0 ///
													  & indexnot("No crypto",currencies_potential_3_13) !=0 ///
													  & indexnot("bitcoin",currencies_potential_3_13) !=0 ///
													  & indexnot("None, with the exception",currencies_potential_3_13) !=0 ///
													  & indexnot("any of the above",currencies_potential_3_13) !=0 ///
													  & indexnot("all of them follow similar patrn of pric",currencies_potential_3_13) !=0 ///													  
													  & indexnot("None. Crypto",currencies_potential_3_13) !=0 


*----- Keep if the keep variable
keep household_id currency choice currencies_potential quantity expectationsvalue typeobjective ///
typeselfreport age country income date   ///
heard_of_crypto plan_to_purchase_12_months first_purchase_time ///
plan_to_increase_holding accept_across_industry how_long_to_be_mainstream ///
company_consider_implement bullish_sector

save "data/working/adjusted_investor",replace




************************************************************************************************************************
*------------------------------------------------------------------------------*
* Only keep the new dataset
*------------------------------------------------------------------------------*
************************************************************************************************************************

*---------- Append together
use "data/working/adjusted_consumer_jan",clear
append using "data/working/adjusted_consumer_july"
save "data/working/adjusted_consumer",replace



*---------- Eliminate strange characters (2014��- 2015; 2016��- 2017)
* consumer
use "data/working/adjusted_consumer",clear
replace first_purchase_time = "2014-2015" if strpos(first_purchase_time,"2014") > 0
replace first_purchase_time = "2016-2017" if strpos(first_purchase_time,"2016") > 0
replace expectationsvalue = "I dont know" if strpos(expectationsvalue,"know") > 0

save "data/working/cleaned_consumer",replace

* investor
use "data/working/adjusted_investor",clear
replace first_purchase_time = "2014-2015" if strpos(first_purchase_time,"2014") > 0
replace first_purchase_time = "2016-2017" if strpos(first_purchase_time,"2016") > 0
replace expectationsvalue = "I dont know" if strpos(expectationsvalue,"know") > 0

save "data/working/cleaned_investor",replace
